class queue():
    def __init__(self):
        self.IN = []
        self.OUT = []
        self.n = 0
    def enqueue(self, a):
        self.IN.append(a)
        self.n += 1
    def dequeue(self):
        if self.n == 0:
            raise Exception('queue underflow')
        if len(self.OUT) == 0:
            while len(self.IN) > 0:
                self.OUT.append(self.IN.pop())
        self.n -= 1
        return self.OUT.pop()

if __name__ == '__main__':
    A = queue()
    for i in xrange(5):
        A.enqueue(i + 1)
    for i in xrange(3):
        print A.dequeue(),
    for i in xrange(5,10):
        A.enqueue(i + 1)
    for i in xrange(7):
        print A.dequeue(),
        
